package com.example.swagger.controller;


import com.example.swagger.model.ProjectUser;
import com.example.swagger.model.User;
import com.example.swagger.util.BaseResult;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Supplier;

@RestController
@RequestMapping("/hello")
@Api(tags = "用户")
public class SwagController {


    @ApiOperation(value = "查询用户", notes = "查询用户")
    @ApiImplicitParams({@ApiImplicitParam(name = "name", value = "姓名", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/getName",method= RequestMethod.POST)
    @ResponseBody
    public User getName(@RequestBody User name) {
        System.out.println(name.toString());
        return name;
    }
    @ApiOperation("获取用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token信息", paramType = "header")
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "请求成功"),
            @ApiResponse(code=401,message = "请求失败"),
    })
//    @GetMapping("getuserinfo")
//    public BaseResult<Supplier> getUserOfLogin(HttpServletRequest request) throws UnsupportedEncodingException {
//        //获取Headers中的参数
//        String token = request.getHeader("token");
//        //获取header，这是从Redis中获取登录信息
//        Supplier user = (Supplier) opsForValue().get(token);
//        if(user != null){
//            return BaseResult.success(user);
//        }
//        return BaseResult.unAuth();
//    }
    @PostMapping("/postuserlist")
    private BaseResult<List<Supplier>> getUser(@RequestBody ProjectUser projectUser){
        List<Supplier> supplier = new LinkedList((Collection) projectUser);
        return BaseResult.success(supplier);
    }
//    @ApiOperation(value="分类", notes="平台")
//    @RequestMapping(value="/Group",method = RequestMethod.POST,produces = "application/json")
//    public void CreateCataLogGroup(@RequestBody CreateCataLogGroup jsonStr, HttpServletRequest request, HttpServletResponse response){
//
//        HashMap<String, Object> resultdata = new HashMap<String, Object>();
//        resultdata.put("group_id", "30703304");
//        JSONObject json = new JSONObject();
//        json.put("code","A-01");
//        json.put("message","处理成功");
//        json.put("data",resultdata);
//        this.renderJson(response, json.toJSONString());
//    }


//    @PostMapping(value = "/add2",produces = "text/html; charset=UTF-8")
//    public String InsertDatas(@RequestBody(required = false) TestVo testVo){
//        Object service = new Object();
//        service.addData(testVo.getT1(),testVo.getT2());
//        return "成功";
//    }

//    @ApiOperation(value = "测试接口", notes = "示例数据：\n" + test)
//    @PostMapping("/test2")
//    public JSONObject test2() {
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("data", "test");
//        return jsonObject;
//    }
//
//    private final static String test="{\n" +
//            "    \"input\":\"test\",\n" +
//            "    \"input2\":\"test2\"\n" +
//            "}";





}